#!/usr/bin/env bash
# install
# install script for wslu
# <https://github.com/wslutilities/wslu>
# Copyright (C) 2019 Patrick Wu
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
BUILD_DIR=`mktemp --tmpdir --directory wslu-install.XXXX`
distro="$(cat /etc/os-release | head -n1 | sed -e 's/NAME=\"//g')"
case $distro in
	*WLinux*|Ubuntu*|*Debian*|*Kali*) sudo apt install -y git;;
	openSUSE*|SLES*) sudo zypper -n install git;;
	Alpine*) sudo apk add git;;
	Arch*) sudo pacman -Syyu git --noconfirm;;
	Scientific*) sudo yum install -y git;;
	*Fedora*|*Rocky*) sudo dnf install -y git;;
	*Gentoo*) sudo emerge -a n dev-vcs/git;;
	*Generic*) [ "fedora" == "$(cat /etc/os-release | grep -e "LIKE=" | sed -e 's/ID_LIKE=//g')" ] && sudo dnf install -y git || exit 1;;
	*) exit 1;;
esac
git clone https://github.com/wslutilities/wslu $BUILD_DIR
cd $BUILD_DIR
bash configure.sh
make
sudo make install
sudo install -m755 extras/scripts/wslu-uninstall /usr/bin
rm -rf $BUILD_DIR
echo -e "\e[32m## wslu installation complete. To uninstall, run 'wslu-uninstall'\033(B\033[m"
